#!/usr/bin/env node

const http = require('http'),
        log = console.log,
        addr = 'http://wangding:123@www.baidu.com:8080/a/b/c?age=20&gender=M#d/e/f';

function print(url){
  log(url.protocol);
  log(url.username);
  log(url.password);
  log(url.hostname);
  log(url.port);
  log(url.pathname);
  log(url.pathname.split('/'));
  log(url.search);
  log(url.hash);
  log(url.searchParams.get('age'));
  log(url.searchParams.get('gender'));
  log();
}
print(new URL(addr));
//process.exit()
http.createServer((req, res) => {
   //const addr1 = `http://${req.headers.host}${req.url}`;
   //print(new URL(addr1));
  log(req.url);
  log(req.headers);
  const urlBase = `http://${req.headers.host}`;
  print(new URL(req.url,urlBase));
  res.end('ok');
}).listen(8080);
